class AddDeterminism < Formula
  desc "Build postprocessor to reset metadata fields for build reproducibility"
  homepage "https://github.com/keszybz/add-determinism"
  url "https://github.com/keszybz/add-determinism/archive/refs/tags/v0.7.2.tar.gz"
  sha256 "232c4f9fdc482dee5e6d38ef45a2c983b88283fe23d6ff4bcb26164b4c9a2dcb"
  license "GPL-3.0-or-later"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_tahoe:   "eeb3e62ac092a45d7c80ad6028866c21e53dd67deca07cd858c60ca08b605115"
    sha256 cellar: :any_skip_relocation, arm64_sequoia: "5c1fcd780d6cd60bb5b5a87a9034396d1fc7e389fbfb162b0bc0133398fcb5e7"
    sha256 cellar: :any_skip_relocation, arm64_sonoma:  "32e47defa47bb9c60faa4590ff747249d0a7a137df8a28f25385ace015f6e407"
    sha256 cellar: :any_skip_relocation, sonoma:        "535ba04c2c5a2252676dcfd043ede6509ed2ed8d982ff3fea3d944d1d51c3aea"
    sha256 cellar: :any_skip_relocation, arm64_linux:   "8320195d668c1822ed3c0d9a9be244f7e022be0812d318339cbcba1009125cc6"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "dcd9b16144899992dbafb28d162ad3796002fe605749650292c46057c7952ced"
  end

  depends_on "pkgconf" => :build
  depends_on "rust" => :build

  uses_from_macos "llvm" => :build
  uses_from_macos "zlib"

  on_linux do
    depends_on "libselinux"
  end

  def install
    ENV["RUSTFLAGS"] = "-C link-arg=-lselinux" if OS.linux?
    system "cargo", "install", *std_cargo_args
  end

  test do
    (testpath/"test.html").write <<~HTML
      <!-- Generated by javadoc (1.2.3) on 2025-01-01 -->
      <meta name="dc.created" content="2025-01-01">
    HTML

    ENV["SOURCE_DATE_EPOCH"] = "0"
    system bin/"add-det", testpath/"test.html"

    assert_match "<!-- Generated by javadoc -->", (testpath/"test.html").read
    assert_match "content=\"1970-01-01\"", (testpath/"test.html").read
  end
end
